/**
 * YRead 阅读模式插件
 * @author yulipu
 *
 * new YRead().init('btnId', callback);
 *
.y-read-mask {
	position:fixed;
	z-index:1127;
	width:100%;
	height:100%;
	top:0;
	left:0;
	background-color:#fbfcf7;
	overflow:auto;
	font-family:'Helvetica Neue',Helvetica,Arial,Sans-serif;
	font-size:14px;
}
.y-read-header {
	position:fixed;
	width:100%;
	top:0;
	left:0;
	height:60px;
	line-height:60px;
	text-align:center;
	background-color:#F8FAED;
	border-bottom:1px solid #EEE;
}
.y-read-container {
	width:960px;
	margin:0 auto;
	padding:80px 0 20px 0;
	line-height:1.7;
}
 */
function YRead() {
	this.config = {
		"cssFile" : Y._CDN_ + "/css/yread.css"
	};
	
	this.doc = document;
	this.maskId = 'yreadmask';
	this.maskObj = null;
	this.headerObj = null;
	this.headerHtml = '阅读';
	this.conObj = null;
}
YRead.prototype = {
	constructor : YRead,
	start : function() {
		var _this = this;
		
		this.initMask();
		this.initHeader();
		this.initContainer();
		// 加载 css
		this.loadCss();
	},
	initMask : function() {
		this.maskObj = this.doc.createElement('div');
		this.maskObj.id = this.maskId;
		this.maskObj.className = 'y-read-mask';
	},
	initHeader : function() {
		this.headerObj = this.doc.createElement('div');
		this.headerObj.className = 'y-read-header';
		this.headerObj.innerHTML = this.headerHtml;
		
		this.maskObj.appendChild(this.headerObj);
	},
	initContainer : function() {
		this.conObj = this.doc.createElement('div');
		this.conObj.className = 'y-read-container';
		
		this.maskObj.appendChild(this.conObj);
	},
	loadCss : function() {
		var link = this.doc.createElement('link');
		link.setAttribute('rel', 'stylesheet');
		link.setAttribute('type', 'text/css');
		link.setAttribute('href', this.config.cssFile);
		
		this.doc.getElementsByTagName('head')[0].appendChild(link);
	},
	open : function() {
		if(!this.doc.getElementById(this.maskId)) {
			this.doc.body.appendChild(this.maskObj);
		}
	},
	close : function(e) {
		if(e.keyCode != 27) return;
		if(!!this.doc.getElementById(this.maskId)) {
			this.doc.body.removeChild(this.maskObj);
		}
	},
	init : function(id, callback) {
		var _this = this;
		
		// 初始化 只执行一次
		this.start();
		
		// 监听 esc
		this.doc.onkeydown = function(e){
			e = e || window.event;
			_this.close(e);
		};
		// 打开
		var obj = this.doc.getElementById(id);
		obj.onclick = function(){
			_this.open();
			if(undefined != callback) {callback(_this.conObj);}
		};
		obj = null;
	}
};
